/* 
 * File:   Config.cpp
 * Author: Bram
 * 
 * Created on January 18, 2013, 9:11 PM
 */

#include "Config.h"

Config* Config::instance = 0;

Config::Config() {
    //loadDefaults();
}

Config::~Config() {
    
}

void Config::loadDefaults()
{
    
    _serverName = "SYNCBOX";
    _serverVersion = "1.001";
    _serverAbout = "BY BRAM KLEIN, JEROEN SCHIPPER en FREEK LAURIJSSEN";
    
    EmptyXMLNodeRepresenter = "[EMPTY]";
    NotExistsRepresenter = "[NOT EXISTS]";
    OkRepresenter = "[OK]";
    
    _baseCommand = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><Command Name=\"\" Sender=\"\" Type=\"\" ><Parameters></Parameters></Command>";
    
    char tmp[FILENAME_MAX];
    getcwd(tmp,FILENAME_MAX);
    CurrentDir = tmp;
    
    #if defined _OS_WIN
        PathSeparator = "\\";
        if(Utility::getInstance()->startsWith(CurrentDir,"/cygdrive/") && CurrentDir.size() > 10)
        {
            CurrentDir = CurrentDir.substr(10);
            string driveLetter = CurrentDir.substr(0,1);
            replace(CurrentDir.begin(), CurrentDir.end(), '/', '\\');
            Utility::getInstance()->toUpper(driveLetter);
            stringstream ss;
            ss << driveLetter << ":" << CurrentDir.substr(1);
            CurrentDir = ss.str();
        }
    #else
        PathSeparator = "/";
    #endif

    if(!Utility::getInstance()->endsWith(CurrentDir,PathSeparator)){
        stringstream ss;
        ss << CurrentDir << PathSeparator;
        CurrentDir = ss.str();
    }
        
    BaseFolderName = "syncbox";
    string baseDir;
    getFullBasePath(baseDir);
    //checkt of de sync dir al gestaat, zo niet maakt ie hem aan
    if(!Utility::getInstance()->directoryExists(baseDir)){
        Utility::getInstance()->createDir(baseDir, baseDir);
    }
}

void Config::getFullBasePath(string & outputPath)
{
    stringstream ss;
    ss << CurrentDir << BaseFolderName << PathSeparator;
    outputPath = ss.str();
}

const string& Config::getServerName()
{
    return _serverName;
}

const string& Config::getServerVersion()
{
    return _serverVersion;
}

const string& Config::getServerAbout()
{
    return _serverAbout;
}

const string& Config::getBaseCommand()
{
    return _baseCommand;
}